package com.ddtech.business.train.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddtech.business.train.entity.TrainPlanUser;
import com.ddtech.business.train.mapper.TrainPlanUserMapper;
import com.ddtech.business.train.service.TrainPlanUserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-09
 */
@Service
public class TrainPlanUserServiceImpl extends ServiceImpl<TrainPlanUserMapper, TrainPlanUser> implements TrainPlanUserService {

    @Override
    public void savePlanUser(String planId, List<TrainPlanUser> userList) {
        QueryWrapper<TrainPlanUser> queryWrapper = new QueryWrapper();
        queryWrapper.eq(TrainPlanUser.PLAN_ID, planId);
        this.remove(queryWrapper);
        userList.forEach(item -> {
            item.setPlanId(planId);
            this.saveOrUpdate(item);
        });
    }

    @Override
    public List<TrainPlanUser> getPlanUserList(String planId) {
        QueryWrapper<TrainPlanUser> queryWrapper = new QueryWrapper();
        queryWrapper.eq(TrainPlanUser.PLAN_ID, planId);
        return this.list(queryWrapper);
    }
}
